<?php

declare(strict_types=1);

namespace app\validate\verify;

use think\Validate;

class StockAdminUpdateValidate extends Validate
{
    protected $rule = [
        'assist_user_id' => 'integer|gt:0',
        'status' => 'in:0,1,2,3',
        'audit_status' => 'in:0,1,2',
        'audit_remark' => 'max:255',
        'seller_qty' => 'integer|egt:0',
        'seller_remark' => 'max:255',
        'seller_media' => 'checkMedia',
    ];

    protected $message = [
        'assist_user_id.integer' => '客服ID格式不正确',
        'assist_user_id.gt' => '客服ID格式不正确',
        'status.in' => '状态不合法',
        'audit_status.in' => '审核状态不合法',
        'audit_remark.max' => '审核备注不能超过255个字符',
        'seller_qty.integer' => '数量必须是整数',
        'seller_qty.egt' => '数量不能为负数',
        'seller_remark.max' => '卖家备注不能超过255个字符',
    ];

    protected $scene = [
        'update' => ['assist_user_id', 'status', 'audit_status', 'audit_remark', 'seller_qty', 'seller_remark', 'seller_media'],
    ];

    protected function checkMedia($value)
    {
        if ($value === null || $value === '') {
            return true;
        }

        if (!is_array($value) && !is_string($value)) {
            return '附件格式不正确';
        }

        return true;
    }
}
